<extend name="Layout/ins_page" />
<block name="content">
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>

    <div  id='maoliandxiaoshouForm'>
        <div class="fieldset-body">

            <!--<form method='post' id="maoliandxiaoshouForm" name="maoliandxiaoshouForm" enctype="multipart/form-data"   class="well form-horizontal">-->
            <div>
            <span>开始时间:</span>
            <input id="start" name="start" class="mini-datepicker" format="yyyy-MM-dd " showTime="true" valueType='string'
                   value="<?php echo date('Y-m-d', time() - 86400 * 7) ?>"/>

            <span>截至时间:</span>
            <input id="end" name="end" class="mini-datepicker" format="yyyy-MM-dd " showTime="true" valueType='string'
                   value="<?php echo date('Y-m-d ') ?>"/>
            </div>
            <div>
                物料名称: <input style="width: 360px" id="itemName" name="itemName" class="mini-textbox"/>
            </div>
            <div>
                <div id="listbox" name="listbox" class="mini-listbox" style="width:420px;height:120px;" onvaluechanged="onListBoxValueChanged"
                     url="/Report/getPingTaiList/" showCheckBox="true" multiSelect="true" >
                    <div property="columns">
                        <div header="平台代码" field="id"></div>
                        <div header="平台名称" field="text"></div>
                    </div>
                </div>
            </div>

            汇总方式：<div id="queryType" name="queryType" class="mini-radiobuttonlist" value="1" repeatItems="4" repeatDirection="horizontal" repeatLayout="table" data="[{'id':1,'text':'合并'},{'id':2,'text':'不合并'}]" textField="text" valueField="id" ></div>

            <div>
            <a class="mini-button" onclick="search()" enabled="" id='query-bt'  style="width:420px; margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a>
            </div>

            <div>
            <a class="mini-button" onclick="exportToexcel()" enabled="" id='export-bt'  style="width:420px; margin-top: 5px">&nbsp;&nbsp;导出&nbsp;&nbsp;</a>
            </div>
            <!--</form>-->

            <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
                 buttons="#tabsButtons"
            >
                <div title="毛利表及销售查询" >

                    <div id="datagrid1" class="mini-datagrid" style="height:430px;width: 100%;"
                         url="/Report/maoliandxiaoshou20171018data" idField="id"
                         allowResize="true"
                         allowCellEdit="true" allowCellSelect="true" multiSelect="true"
                         allowCellValid="true" oncellvalidation="" showPager="false"
                    >

                        <div property="columns">

                            <div field="itemCode"  headerAlign="center"  >物料号
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="itemName"  headerAlign="center"  >物料名
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumQty"  headerAlign="center"  >数量
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumProfit"  headerAlign="center"  >毛利
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="profitRate"  headerAlign="center"  >毛利率%
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="avgPrice"  headerAlign="center"  >销售单价
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumLineTotal"  headerAlign="center"  >销售金额
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="avgStockprice"  headerAlign="center"  >采购单价
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumLineStockPrice"  headerAlign="center"  >库存价值
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumBankCharge"  headerAlign="center"  >银行费用
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="avgBankCharge"  headerAlign="center"  >平均费率
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumCalcExpressFee"  headerAlign="center"  >快递费用
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="avgCalcExpressFee"  headerAlign="center"  >平均快递费用
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumGiftCount"  headerAlign="center"  >赠品件数
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>
                            <div field="sumGiftCost"  headerAlign="center"  >赠品成本
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="sumGiftAddExpressFee" headerAlign="center"  >赠品运费
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="sumAddExpressFee" headerAlign="center"  >物流附加
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="sumCalcTax" headerAlign="center"  >税
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                            <div field="shortname" headerAlign="center"  >平台
                                <input property="" class="mini-textbox" style="width:100%;" />
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    </body>

    <script>
        function popItem(itemCode) {
            mini.open({
                url:  "Report/wuliaojikucunPOP20171018/itemCode/"+itemCode+"/",
                title: "",
                width: 800,
                height: 380,
                ondestroy: function (action) {
                    if (action == "ok") {

                    }

                }
            });

        }
    </script>

    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.setPageSize(50000);
        grid.on("drawcell", function (e) {
            var record = e.record,
                column = e.column,
                field = e.field,
                value = e.value;

            if (field == "itemCode") {
                e.cellHtml = "<a href=\"javascript:popItem(\'"+record.itemCode+"\')\" >" +value+ "</a>";
            }

            //格式化日期
            if (field == "ctime") {
                if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");

            }

            if (field == "relevant_link"||field == "similar_brand_link"||field == "top_link") {
                e.cellHtml = '<a href="' + value + '"  target="_blank"  >' +value+ '</a>';
            }

            if (field == "b_name") {
                var url="/SapSupplier/brandedit/id/";
                e.cellHtml = '<a href="' + url+record.b_id + '"  target="_blank"  >' +value+ '</a>';
            }

            if (field == "logo") {
                e.cellHtml = '<img src="' + value + '"  style="width:50px" >';
            }

            if (field == "s_price") {
                e.cellHtml = value+"<br>"+record.e_price;
            }

//            if(record.examine_status!=1)
//                e.cellStyle = "background:#f9a8a8";

            if (field == "examine_status") {
                e.cellHtml =value==1?"通过":(value==0?"待审核":'未通过') ;
            }

        });

        function onListBoxValueChanged(e) {
            var listbox = e.sender;
            var value = listbox.getValue();
        }

        function checkPT(ptlist) {

            if(ptlist){}
            else{
                alert('平台不能为空');
                return true;
            }
        }

        function search(){
            var startDate = mini.get('start').getValue();
            var endDate = mini.get('end').getValue();
            var itemName = mini.get('itemName').getValue();
            var ptlist = mini.get('listbox').getValue();
            var queryType = mini.get('queryType').getValue();

            if(checkPT(ptlist))
            {
                return;
            }

            grid.load({startDate:startDate,endDate:endDate,itemName:itemName,ptlist:ptlist,queryType:queryType})
        }

        function exportToexcel(){

            var startDate = mini.get('start').getValue();
            var endDate = mini.get('end').getValue();
            var itemName = mini.get('itemName').getValue();
            var ptlist = mini.get('listbox').getValue();
            var queryType = mini.get('queryType').getValue();

            if(checkPT(ptlist))
            {
                return;
            }

            var f=document.createElement("form");
            f.action="/Report/maoliandxiaoshou20171018excel";
            f.method="post";
            f.innerHTML="<input type='hidden' name='startDate' value='"+startDate+"'/>"+
                "<input type='hidden' name='endDate' value='"+endDate+"'/>"+
                "<input type='hidden' name='itemName' value='"+itemName+"'/>"+
                "<input type='hidden' name='ptlist' value='"+ptlist+"'/>"+
                "<input type='hidden' name='queryType' value='"+queryType+"'/>"
            ;
            document.body.appendChild(f);
            f.submit()

//            $.post("/Report/maoliandxiaoshou20171018excel", {startDate:startDate,endDate:endDate,itemName:itemName,ptlist:ptlist},function(result){
//            });

//                $.ajax({
//                url: "/Report/maoliandxiaoshou20171018excel",
//                type: "post",
//                async:false,
//                data: {startDate:startDate,endDate:endDate,itemName:itemName,ptlist:ptlist},
//                success: function (text) {
//                    var obj = window.open("about:blank");
//                    obj.document.write(text);
//                }
//            });

        }

    </script>
</block>

